//
// Created by fengg on 2020/5/24.
//

#include <stdio.h>
#include <stdlib.h>


int __get_max_index(const int *lpArray,int iLower,int iUpper){
    int iMax = -99999;
    int iMaxIndex = -1;
    int i;
    for (i = iLower; i <= iUpper; ++i) {
        if(lpArray[i] > iMax){
            iMax = lpArray[i];
            iMaxIndex = i;
        }
    }
    return iMaxIndex;
}

int __get_min_index(const int *lpArray,int iLower,int iUpper){
    int iMin = 99999;
    int iMinIndex = -1;
    int i;
    for (i = iLower; i <= iUpper; ++i) {
        if(lpArray[i] < iMin){
            iMin = lpArray[i];
            iMinIndex = i;
        }
    }
    return iMinIndex;
}

int DisplayIArray(int *lpArray,int iLower,int iUpper){
    int i;
    for (i = iLower; i <= iUpper; ++i) {
        printf("%d ",lpArray[i]);
    }
    putchar('\n');
    return 0;
}


int BubbleSort(int *lpArray,int iLower,int iUpper){
    int iCurrUpper = iUpper;
    int iCurrLower = iLower;
    int iTemp,iIndex;
    for (;iCurrLower < iCurrUpper;) {

        iTemp = lpArray[iCurrLower];
        iIndex = __get_min_index(lpArray,iCurrLower,iCurrUpper);
        lpArray[iCurrLower] = lpArray[iIndex];
        lpArray[iIndex] = iTemp;

        iTemp = lpArray[iCurrUpper];
        iIndex = __get_max_index(lpArray,iCurrLower,iCurrUpper);
        lpArray[iCurrUpper] = lpArray[iIndex];
        lpArray[iIndex] = iTemp;

        --iCurrUpper;
        ++iCurrLower;

        DisplayIArray(lpArray,iLower,iUpper);
    }
}

int main(){
    int *lpArray;
    int iNumber;
    int i;
    scanf("%d",&iNumber);
    lpArray = malloc(sizeof(int)*iNumber);
    for (i = 0; i < iNumber; ++i) {
        scanf("%d",&lpArray[i]);
    }
    DisplayIArray(lpArray,0,iNumber-1);
    BubbleSort(lpArray,0,iNumber-1);

    return 0;
}
